package gof.com.yew.prototype;

/**
 * 原型模式
 *深克隆---克隆所有的属性 
 */
//1.实现Cloneable接口
public class Sheep1 implements Cloneable {

	private String name;

	private Address1 address;

	public Sheep1(String name, Address1 address) {
		this.name = name;
		this.address = address;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Address1 getAddress() {
		return address;
	}

	public void setAddress(Address1 address) {
		this.address = address;
	}

	//2.重写Clone方法
	public  Object  Clone() throws CloneNotSupportedException {
		Sheep1 sheep1 = (Sheep1)super.clone();
		sheep1.address= (Address1)address.Clone();
		return  sheep1;
	}

}

class Address1 implements Cloneable {

	private String  cuntry;
	
	private String loc;

	public Address1(String cuntry, String loc) {
		this.cuntry = cuntry;
		this.loc = loc;
	}

	public String getCuntry() {
		return cuntry;
	}

	public void setCuntry(String cuntry) {
		this.cuntry = cuntry;
	}

	public String getLoc() {
		return loc;
	}

	public void setLoc(String loc) {
		this.loc = loc;
	}
	
	//2.重写Clone方法
		public  Object  Clone() throws CloneNotSupportedException {
			return  super.clone();
		}
	
}